package com.wzxy.spider.wx.service.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wzxy.spider.wx.entity.Topic;
import com.wzxy.spider.wx.repository.TopicRepository;
import com.wzxy.spider.wx.service.ITopicService;
import com.wzxy.wzinfo.service.impl.MyJpaService;

@Service("topicService")
public class TopicService  extends MyJpaService<Topic,Integer> implements ITopicService {

	private TopicRepository topicRepository;

	@Autowired
	public void setTopicRepository(TopicRepository topicRepository) {
		this.topicRepository = topicRepository;
		super.setJpaRepository(topicRepository);
		super.setJpaSpecificationExecutor(topicRepository);
	}
	
	@PersistenceContext
	protected EntityManager em;

	public List<Topic> saveAll(List<Topic> list_t) {
		return topicRepository.save(list_t);
	}
	
	public void saveList(List<Topic> list_t) {
		Topic t;
		for (int j=list_t.size()-1; j>0; j--) {
			t = null;
			t = topicRepository.findByFileid(list_t.get(j).getFileid());
			if(t!=null){
				System.out.println("topic 存在！！！");
				list_t.remove(j);
			}
		}
		List<Topic> t1 = topicRepository.save(list_t);
		System.out.println("aaaaaaaa"+t1.size());
	}

	@Override
	public Topic findByFileid(String fileid) {
		// TODO Auto-generated method stub
		return topicRepository.findByFileid(fileid);
	}
	
	
}
